package com.ruoyi.business.payment.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.business.payment.domain.TRegisterPaymentOrder;
import com.ruoyi.business.payment.vo.*;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * 预支付订单信息Service接口
 *
 * @author Tellsea
 * @date 2025-06-22
 */
public interface ITRegisterPaymentOrderService extends IService<TRegisterPaymentOrder> {

    /**
     * 分页查询
     *
     * @param entity
     * @return
     */
    TableDataInfo<TRegisterPaymentOrderDto> queryList(TRegisterPaymentOrderVo entity);

    /**
     * 查询全部
     *
     * @param entity
     * @return
     */
    List<TRegisterPaymentOrderDto> queryAll(TRegisterPaymentOrderVo entity);

    TableDataInfo<TRegisterPaymentOrderDeptDto> queryByDept(TRegisterPaymentOrderVo entity);

    /**
     * 根据ID查询
     *
     * @param orderId
     * @return
     */
    TRegisterPaymentOrderDto queryById(Long orderId);

    TRegisterPaymentOrderDto queryByRegisterId(Long registerId);

    /**
     * 统计查询
     *
     * @param entity
     * @return
     */
    TRegisterPaymentOrderStatDto queryByStat(TRegisterPaymentOrderVo entity);

    /**
     * 关闭订单
     *
     * @param orderId 订单id
     * @return rsp
     */
    void closeOrder(Long orderId) throws Exception;

    /**
     * 创建预支付订单
     *
     * @param registerId 报名id
     */
    Long createPrePaymentOrder(Long registerId) throws Exception;

    /**
     * 支付成功后的数据返回
     *
     * @param orderId           订单id
     * @param channelOrderNo     支付中心的订单id
     * @param payChannelOrderNo
     * @param isOnline
     */
    void handlePaymentCallback(Long orderId, String channelOrderNo, String payChannelOrderNo, BigDecimal amount, Date paymentDate, boolean isOnline);

    /**
     * 退款成功后的回调
     * param paymentStatus 返回状态
     */
    void handleRefundCallback(String busNo, String refundBusNo, String channelRefundNo, BigDecimal refundAmount, Date refundDate);

    /**
     * 添加退款申请
     *
     * @param orderId 退款单id
     * @param amount  退款金额
     * @param reason  退款原因
     */
    void addRefundApply(Long orderId, BigDecimal amount, String reason) throws ParseException;

    @Transactional
    void queryForTimeOutOrder() throws Exception;

    List<TRegisterWillExpirationOrderVo> queryWillExpirationOrder() throws Exception;

    /**
     * 处理流程审批
     *
     * @param approvalId 流程id
     * @param status     审批状态
     * @param opinion    审批意见
     */
    void processApproval(String approvalId, Integer status, String opinion) throws Exception;

}
